<!-- 排班管理 -->
<template>
  <div class="dashboard-container transport-task customer-list-box">
    <!-- 顶部模糊搜索 -->
    <el-card class="fuzzy-search">
      <el-form
        :ref="pageParam"
        :model="pageParam"
      >
        <el-row>
          <el-col :span="8">
            <el-form-item>
              <span>员工账号：</span>
              <el-input
                v-model="pageParam.name"
                type="text"
                style="width: 282.06px; height: 40px;"
                placeholder="请输入员工账号"
              >
              </el-input></el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span>员工账号：</span>
              <el-input
                v-model="pageParam.employeeNumber"
                type="text"
                style="width: 282.06px; height: 40px;"
                placeholder="请输入员工账号"
              >
              </el-input></el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span>工作模式：</span>
              <el-select
                v-model="value"
                placeholder="请选择"
                style="width: 282.06px;"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <span style="margin-left: 25px;">月份：</span>
            <el-form-item style="width: 282.06px; height: 40px; ">
              <el-date-picker
                v-model="pageParam.month"
                type="month"
                placeholder="选择月"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <span>所属机构：</span>
              <el-input
                type="text"
                style="width: 282.06px; height: 40px;"
                placeholder="请输入员工账号"
              >
              </el-input></el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <el-button
                type="primary"
                @click="selectle"
              >搜索</el-button>
              <el-button @click="selectReset">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <!-- table数据展示 -->
    <el-card class="table-data">
      <!-- 操作按钮 -->
      <div
        class="button-pai"
      >
        <el-button
          type="primary"
          @click="$router.push('workArrange-setting')"
        >设置排班</el-button>
        <el-button @click="schedulingsr">绑定排班</el-button>
      </div>
      <el-table
        :data="items"
      >
        <el-table-column
          type="selection"
          width="60"
          height="23"
          fixed
        ></el-table-column>
        <el-table-column
          fixed
          label="员工账号"
          width="100"
          height="250"
          prop="employeeNumber"
        ></el-table-column>
        <el-table-column
          fixed
          label="员工姓名"
          width="120"
          height="23"
          prop="name"
        ></el-table-column>
        <el-table-column
          fixed
          prop="phone"
          label="员工电话"
          width="120"
          height="23"
        ></el-table-column>
        <el-table-column
          fixed
          prop="userType"
          label="员工角色"
          width="100"
          height="23"
        ></el-table-column>
        <el-table-column
          fixed
          prop="workPatternName"
          label="当前工作模式"
          width="110"
          height="23"
        ></el-table-column>
        <el-table-column
          v-for="(item, index) in columnCount"
          :key="index"
          :label="`${index + 1}`"
        >
          <template v-slot="scope">
            <span
              v-if="scope.row.workSchedules[index] === true"
              class="spantrue"
            >{{ scope.row.workSchedules[index] === true ? '上' : '休' }}</span>
            <span
              v-else
              class="spanlist"
            >{{ scope.row.workSchedules[index] === true ? '上' : '休' }}</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-box">
        <el-pagination
          :current-page="pageParam.page"
          :page-size="pageParam.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        >
        </el-pagination>
      </div>
    </el-card>
    <el-dialog
      title="人工调整"
      width="566px"
      :visible.sync="scheduling"
    >
      <el-form>
        <el-row>
          <el-col style="width: 100%;">
            <el-form-item style="text-align: center;">
              <el-radio
                v-model="radio"
                label="1"
              >礼拜制</el-radio>
              <el-radio
                v-model="radio"
                label="2"
              >连续制</el-radio>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item>
          <el-row
            type="flex"
            justify="center"
          >
            <el-col
              :span="12"
              style="left: 30px;"
            >
              <span>模式名称</span>
            </el-col>
            <el-col>
              <el-select
                v-model="value"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-row>

        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { selectList } from '@/api/workarrange'
export default {
  data() {
    return {
      multipleSelection: [],
      options: [{
        value: '选项1',
        label: '黄金糕'
      }, {
        value: '选项2',
        label: '双皮奶'
      }, {
        value: '选项3',
        label: '蚵仔煎'
      }],
      value: '',
      pageParam: {
        page: 1,
        pageSize: 10,
        name: '',
        employeeNumber: '',
        workPatternId: null,
        month: ''
      },
      // 工作模式
      workPatternName: [],
      // 数据
      items: [],
      columnCount: 30,
      // 天数状态
      workScheduless: [],
      // 总条数
      total: 0,
      // 绑定排版弹出框
      scheduling: false,
      // 弹窗单选
      radio: '0'
    }
  },
  created() {
    this.selectList()
  },
  methods: {
    // 绑定排班
    schedulingsr() {

    },
    // 绑定排版取消
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {})
    },
    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
    },
    // 页数切换
    async handleCurrentChange(val) {
      this.pageParam.page = Number(val)
      const red = await selectList(this.pageParam)
      this.items = red.data.items
    },

    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      } else {
        this.$refs.multipleTable.clearSelection()
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 查询
    selectle() {
      this.selectList()
    },
    // 重置
    selectReset() {
      this.pageParam.page = 1
      this.pageParam.pageSize = 10
      this.pageParam.employeeNumber = ''
      this.pageParam.name = ''
      this.pageParam.workPatternId = null
      this.pageParam.month = ''
      this.workScheduless = []
      this.selectList()
    },
    // 获取数据
    async selectList () {
      const red = await selectList(this.pageParam)
      this.workPatternName.push(red.data.workPatternName)
      this.total = Number(red.data.counts)
      this.pageParam.page = red.data.page
      this.pageParam.pageSize = red.data.pageSize
      this.items = red.data.items
      console.log(red)
      this.items.forEach((item, index) => {
        if (Array.isArray(item.workSchedules)) {
          const obj = item.workSchedules.reduce((acc, curr, index) => {
            acc[index] = curr
            return acc
          }, {})
          this.workScheduless.push(obj)
        }
      })
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep th.date{
  .cell{
    padding-left: 17px!important;
  }
}
.el-form-item {
  display: inline-block;
}
.spanlist {
  display: inline-block;
  width: 25px;
  height: 25px;
  text-align: center;
  background: #eff3f8;
  border-radius: 50%;
  border: 1px solid #d8dde3;
}
.spantrue {
  display: inline-block;
  width: 25px;
  height: 25px;
  text-align: center;
  background: #ffeeeb;
  border-radius: 50%;
  color: #e15536;
  border: 1px solid #e15536;
}
.work {
  width: 24px;
  height: 24px;
  background: #ffeeeb;
  border: 1px solid #e15536;
  border-radius: 50%;
  text-align: center;
  color: #e15536;
  font-size: 13px;
}
.history-name {
  width: auto !important;
  ::v-deep .el-input__inner {
    width: 293px;
  }
}

.workArrange-manage-people-setting {
  ::v-deep .el-dialog__body {
    padding: 30px 50px 10px 50px !important;
  }
  ::v-deep .el-dialog__footer {
    padding-bottom: 40px;
  }
}

.work-type {
  ::v-deep .el-form-item__content {
    margin-left: 40px !important;
  }
  ::v-deep .el-radio:first-child {
    margin-right: 80px !important;
  }
  ::v-deep.el-radio__label {
    font-weight: bold;
    color: #333333;
  }
}

.dialog-footer {
  .el-button {
    width: 89px;
    height: 36px;
    padding: 10px 20px;
  }
}

.rest {
  width: 24px;
  height: 24px;
  background: #eff3f8;
  border: 1px solid #d8dde3;
  border-radius: 50%;
  text-align: center;
  color: #20232a;
  font-size: 13px;
}

.alert {
  margin: 10px 0px;
}
.pagination {
  margin-top: 40px;
}
.transport-task ::v-deep .el-table td,
.el-table th {
  padding: 12px 0;
  min-width: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: left;
  overflow: hidden;
}

// 下拉框
::v-deep .el-select {
  width: 100%;
}

/*定义滚动条轨道 内阴影+圆角*/
::v-deep .el-table--scrollable-x .el-table__body-wrapper {
  padding-bottom: 5px;
  margin-bottom: 5px;
  &::-webkit-scrollbar {
    height: 10px;
  }

  /*定义滑块 内阴影+圆角*/
  &::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background-color: rgba(144, 147, 153, 0.3);
  }

  &::-webkit-scrollbar-track-piece {
    margin-right: 3px;
    margin-left: 3px;
  }
}
::v-deep .el-card{
  overflow: initial;
}
</style>

<style lang="scss" scoped>
.customer-list-box {
  padding: 3px 20px;
  box-sizing: border-box;
}
.pagination-box {
  width: 100%;
  height: 100px;
  padding-top: 20px;
}
.el-pagination {
  text-align: center;
}
.button-pai {
  margin-bottom: 23px;
  padding-left: 9px;
  padding-top: 5px;
}
.fuzzy-search {
  border-radius: 4px;
  width: 1286.2px;
  height: 161.6px;
  margin-top: 20px;
  padding: 0px 20px;
}
.label {
font-size: 14px;
font-weight: 400;
}
.body {
right: 10px;
}
input {
  border: 1px solid #dcdfe6;
  padding-right: 30px;
  border-radius: 5px;
  padding-left: 10px;
  color: #606266;
}
.table-data {
  margin-top: 20px;
  border-radius: 4px;
}
</style>
